home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0072_Real mode in windows.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  1.4 KB  |  51 lines

  1.  
  2. {Here is the code I promised to sent you. It works nice. You can read
  3. any part of the real-mode low memory with it.}
  4.  
  5. function allocRealModePointer(var P: pointer; Size: longInt): boolean;
  6. var
  7.   Selector,
  8.   base : word;
  9.   LinearBase : longint;
  10. begin
  11.   result := false;
  12.   LinearBase := MakeLong(0,hiword(longint(p)) shr 12) +
  13.                   hiword(longint(P)) shl 4 + loword(longint(P));
  14.                   {converts 20-bit address into a 32-bit one}
  15.                   {i.e. $ffff:0006 into $000ffff6}
  16.   Selector := AllocSelector(DSeg); {Copies DSeg Selector properties }
  17.   base := SetSelectorBase(Selector, LinearBase);
  18.   SetSelectorLimit(Selector, Size);
  19.   if (Selector <> 0) and (base<>0) then  begin
  20.     P := Ptr(Selector, 0);
  21.     result := true;
  22.   end;
  23. end;
  24.  
  25. function freeRealModePointer(var p: pointer): boolean;
  26. var
  27.   fr : Word;
  28. begin
  29.   fr := FreeSelector(hiword(longint(p)));
  30.   {seletor is at hiword(p)}
  31.   if (fr=0) then begin {ok}
  32.     p := nil;
  33.     result := true;
  34.   end else begin    {fail}
  35.     result := false;
  36.   end;
  37. end;
  38.  
  39. { code Test:    The Rom-Bios' date is allways at $ffff:0005 (real-mode)}
  40.  
  41. var
  42.   P: pChar;
  43. begin
  44.   P := Ptr($FFFF, $0005);   {FFFF5 -> data da Rom-Bios}
  45.   if AllocRealModePointer(Pointer(p), 8) then {8 chars to RomBios' date}
  46.   begin
  47.     { Use p to read ROM Bios' date here}
  48.     FreeRealModePointer(Pointer(p));   {dispose p}
  49.   end;
  50. end.
  51.